package cn.tedu.zhyl.nurseManager.controller;

import cn.tedu.zhyl.base.response.JsonResult;
import cn.tedu.zhyl.base.response.PageResponse;
import cn.tedu.zhyl.nurseManager.pojo.dto.NursePlanParam;
import cn.tedu.zhyl.nurseManager.pojo.dto.NursePlanQuery;
import cn.tedu.zhyl.nurseManager.pojo.vo.NursePlanVO;
import cn.tedu.zhyl.nurseManager.service.NursePlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/nurse/plan/")
public class NursePlanController {
    @Autowired
    private NursePlanService nursePlanService;

    @RequestMapping("select/{page}/{limit}")
    public JsonResult<PageResponse<NursePlanVO>> select(NursePlanQuery nursePlanQuery,
                                                        @PathVariable Integer page,
                                                        @PathVariable Integer limit){
        log.debug("NursePlanController.select param:{}",nursePlanQuery);
        PageResponse<NursePlanVO> nursePlanVOList = nursePlanService.select(nursePlanQuery,page,limit);
        return JsonResult.ok(nursePlanVOList);
    }

    // 根据护理计划id查询计划里面项目
    @GetMapping("get/{planId}")
    public JsonResult<List<Map<String,Object>>> getItemsByPid(@PathVariable Integer planId){
        List<Map<String,Object>> list =  nursePlanService.getItemsByPid(planId);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(@RequestBody NursePlanParam planParam){
        nursePlanService.save(planParam);
        return JsonResult.ok();
    }

    @GetMapping("delete/{planId}")
    public JsonResult deletePlan(@PathVariable Integer planId){
        nursePlanService.deletePlan(planId);
        return JsonResult.ok();
    }
}
